import java.util.Scanner;
import java.util.Stack;

public class Solution {
    public boolean isValid(String s){
        Stack<Character> stack = new Stack<>();
        int len = s.length();
        for (int i = 0; i < len; i++) {
            char ch1 = s.charAt(i);
            if(ch1 == '{' || ch1 == '[' || ch1 == '('){
                stack.push(ch1);//将左括号入栈
            }else{
                if(stack.isEmpty()){
                    return false;
                }
                char ch2 = stack.peek();//获取入栈的左括号，与右括号进行匹配
                if((ch2=='{'&&ch1=='}') || (ch2=='['&&ch1==']') || (ch2=='('&&ch1==')')){
                    stack.pop();
                }else {
                    return false;
                }
            }
        }
        if(!stack.isEmpty()){
            return false;
        }
        return true;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextLine()){
            String s = in.nextLine();
            Solution solution = new Solution();
            boolean result = solution.isValid(s);
            System.out.println(result);
        }
    }
}
